package com.qian.service.ddj.serviceImpl;

import com.qian.api.ddj.model.DfBusiness;
import com.qian.api.ddj.service.IDfBusinessService;
import com.qian.service.ddj.dao.DfBusniessRepository;
import com.qian.service.ddj.entity.DdjDfBusiness;
import com.yaowk.api.common.PageReq;
import com.yaowk.api.common.PageResp;
import com.yaowk.service.common.BaseRepository;
import com.yaowk.service.common.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DfBusinessService extends BaseServiceImpl<DfBusiness,DdjDfBusiness,Integer>implements IDfBusinessService {
    @Autowired
    private DfBusniessRepository dao;

    @Override
    public DfBusiness save(DfBusiness model) {
        if (model.isNew()){
            model = super.simpleSave(model);
        }else{
            DdjDfBusiness entity = dao.findOne(model.getId());
            if (isNotEmpty(model.getAccount())){
                entity.setAccount(model.getAccount());
            }
            if (isNotEmpty(model.getBackup1())){
                entity.setBackup1(model.getBackup1());
            }
            if (isNotEmpty(model.getBackup2())){
                entity.setBackup2(model.getBackup2());
            }
            if (isNotEmpty(model.getBackup3())){
                entity.setBackup3(model.getBackup3());
            }
            if (isNotEmpty(model.getBackup4())){
                entity.setBackup4(model.getBackup4());
            }
            if (isNotEmpty(model.getBackup5())){
                entity.setBackup5(model.getBackup5());
            }
            if (isNotEmpty(model.getBalance())){
                entity.setBalance(model.getBalance());
            }
            if (isNotEmpty(model.getName())){
                entity.setName(model.getName());
            }
            if (isNotEmpty(model.getRemark())){
                entity.setRemark(model.getRemark());
            }
            if (isNotEmpty(model.getSecretKey())){
                entity.setSecretKey(model.getSecretKey());
            }
            if (isNotEmpty(model.getStatus())){
                entity.setStatus(model.getStatus());
            }
            if (isNotEmpty(model.getFee())){
                entity.setFee(model.getFee());
            }
            if (isNotEmpty(model.getBeginMoney())){
                entity.setBeginMoney(model.getBeginMoney());
            }
            if (isNotEmpty(model.getEndMoney())){
                entity.setEndMoney(   model.getEndMoney());
            }
            model = entity2model(dao.save(entity));
        }
        return model;
    }

    @Override
    protected BaseRepository getDao() {
        return dao;
    }

    @Override
    protected DdjDfBusiness model2Entity(DfBusiness model) {
        DdjDfBusiness entity = null;
        if (isNotEmpty(model)){
            entity = new DdjDfBusiness();
            entity.setId(model.getId());
            entity.setAccount(model.getAccount());
            entity.setBackup1(model.getBackup1());
            entity.setBackup2(model.getBackup2());
            entity.setBackup3(model.getBackup3());
            entity.setBackup4(model.getBackup4());
            entity.setBackup5(model.getBackup5());
            entity.setBalance(model.getBalance());
            entity.setName(model.getName());
            entity.setSecretKey(model.getSecretKey());
            entity.setStatus(model.getStatus());
            entity.setRemark(model.getRemark());
            entity.setBalance(model.getBalance());
            entity.setFee(model.getFee());
            entity.setBeginMoney(model.getBeginMoney());
            entity.setEndMoney(model.getEndMoney());

        }
        return entity;
    }

    @Override
    protected DfBusiness entity2model(DdjDfBusiness entity) {
        DfBusiness model = null;
        if (isNotEmpty(entity)){
            model = new DfBusiness();
            model.setId(entity.getId());
            model.setAccount(entity.getAccount());
            model.setBackup1(entity.getBackup1());
            model.setBackup2(entity.getBackup2());
            model.setBackup3(entity.getBackup3());
            model.setBackup4(entity.getBackup4());
            model.setBackup5(entity.getBackup5());
            model.setName(entity.getName());
            model.setRemark(entity.getRemark());
            model.setSecretKey(entity.getSecretKey());
            model.setBalance(entity.getBalance());
            model.setStatus(entity.getStatus());
            model.setFee(entity.getFee());
            model.setBeginMoney(entity.getBeginMoney());
            model.setEndMoney(entity.getEndMoney());
        }
        return model;
    }
}
